package co.yixiang.yshop.module.order.controller.app.rechargeorder;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.security.core.annotations.PreAuthenticated;
import co.yixiang.yshop.module.order.controller.app.rechargeorder.vo.AppRechargeOrderCreateReqVO;
import co.yixiang.yshop.module.order.service.rechargeorder.RechargeFacade;
import co.yixiang.yshop.module.order.service.rechargeorder.RechargeOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Tag(name = "APP - 充值模块")
@RequestMapping("/recharge-order")
public class AppRechargeOrderController {

    @Resource
    private RechargeFacade rechargeFacade;

    @Resource
    private RechargeOrderService rechargeOrderService;

    @PreAuthenticated
    @PostMapping(value = "/create")
    @Operation(summary = "充值")
    public CommonResult<String> create(@Valid @RequestBody AppRechargeOrderCreateReqVO createReqVO) throws Exception {
        return success(rechargeFacade.create(createReqVO));
    }

    @PreAuthenticated
    @GetMapping(value = "/isPay")
    @Operation(summary = "支付结果查询")
    public CommonResult<Integer> isPay(@Valid String id){
        return success(rechargeOrderService.isPay(id));
    }
}
